package com.zhou.common.mybatis.template.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.zhou.common.lib.model.Response;
import com.zhou.common.lib.util.BeanUtil;
import com.zhou.common.mybatis.template.entity.FavGroup;
import com.zhou.common.mybatis.template.model.ao.FavGroupAo;
import com.zhou.common.mybatis.template.model.vo.FavGroupAllVo;
import com.zhou.common.mybatis.template.service.impl.FavGroupServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 收藏组 前端控制器
 * </p>
 *
 * @author zxf
 * @since 2023-04-15
 */
@Api(tags = "收藏组")
@ApiSupport(order = 285)
@RestController
@RequestMapping("/favourite/group")
public class FavGroupController {

    @Autowired
    private FavGroupServiceImpl favGroupService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "查询全部")
    @GetMapping("/all")
    public Response<List<FavGroupAllVo>> queryALL(){
        List<FavGroupAllVo> favGroupAllVos = favGroupService.queryALL();
        return Response.success(favGroupAllVos);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "查询收藏列表")
    @GetMapping("/")
    public Response<List<FavGroup>> list(){
        List<FavGroup> favGroupAllVos = favGroupService.list();
        return Response.success(favGroupAllVos);
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增收藏列表")
    @PostMapping("/")
    public Response<List<FavGroup>> add(@RequestBody FavGroupAo ao){
        FavGroup favGroup = BeanUtil.copyObject(ao, FavGroup.class);
        favGroupService.save(favGroup);
        return Response.success();
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增收藏列表")
    @DeleteMapping("/{id}")
    public Response delete(@PathVariable Long id){
        favGroupService.delete(id);
        return Response.success();
    }


}
